<?php

namespace App\Http\Controllers\Api\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Facades\Utils\LogUtil;
use App\Exceptions\ValidateParameterException;
use Auth;

class LoginController extends Controller
{
    /**
     * 后台用户登录
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function login(Request $request){

        $data = $request->all();

        if (!Auth::attempt(['uname' => $data['uname'], 'password' => $data['password']])) {
            throw new ValidateParameterException('您的账号或者密码错误，请重新输入');
        }

        LogUtil::loginLog(Auth::user()->name);

        return formatJsonResponse();

    }

    /**
     * 后台登出
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function logout(Request $request){

    	$userName = Auth::user()->name;

    	Auth::logout();

    	LogUtil::logoutLog($userName);

    	return formatJsonResponse();
    }
}
